package com.redpacketcover.rc.carts;

import android.widget.GridView;

import androidx.annotation.NonNull;

import com.redpacketcover.rc.R;
import com.redpacketcover.rc.adapter.CartsListAdapter;
import com.redpacketcover.rc.base.BasicActivity;
import com.redpacketcover.rc.bean.GoodsRecord;
import com.redpacketcover.rc.common.TitleBar;
import com.redpacketcover.rc.goods.GoodsPresenter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

import java.util.ArrayList;
import java.util.List;

public class CartsActivity extends BasicActivity<GoodsPresenter> {

    private TitleBar mtitlebar;
    private CartsListAdapter mcartslist;

    private List<GoodsRecord> mList = new ArrayList<>();

    private Boolean isPullRefresh = false; // 是否下拉刷新状态

    private GridView grid_photo;
    private SmartRefreshLayout refreshLayout;

    @Override
    protected int initLayout() {
        return R.layout.carts_layout;
    }

    @Override
    protected GoodsPresenter createPresenter() {
        return new GoodsPresenter();
    }

    @Override
    protected void initViews() {
        mtitlebar = findViewById(R.id.title_bar);
        grid_photo = findViewById(R.id.grid_photo);
        refreshLayout = findViewById(R.id.refreshLayout);

        mcartslist = new CartsListAdapter(this);
        grid_photo.setAdapter(mcartslist);
        refreshLayout.autoRefresh();
        refreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                refreshLayout.resetNoMoreData(); //恢复没有更多
                isPullRefresh = true;
                initData();
            }
        });
        mtitlebar.setOnLeftIconClickListner(new TitleBar.OnLeftIconClickListener() {
            @Override
            public void onLeftIconClick() {
                finish();
            }
        });
    }

    @Override
    protected void initData() {
        mPresenter.getCartsList();
    }
}
